<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:inline="javascript">
        $(function () {
            $.get("/plays/clubs",function (data) {
                for (club of data){
                    if (club.cid == [[${play.cid}]]){
                        $("select").append("<option value='"+club.cid+"' selected>"+club.cname+"</option>")
                    }else{
                        $("select").append("<option value='"+club.cid+"'>"+club.cname+"</option>")
                    }
                }
            },"json")
        })
        $(function () {
            $("form").submit(function () {
                if ($("[name=pname]").val()==""){
                    alert("球员姓名不能为空")
                    return false;
                }else if ($("[name=birthday]").val()==""){
                    alert("日期不能为空")
                    return false;
                }else if ($("[name=height]").val()==""){
                    alert("身高不能为空")
                    return false;
                }else if ($("[name=weight]").val()==""){
                    alert("体重不能为空")
                    return false;
                } else if ($("[name=cid]").val()==""){
                    alert("请选择所属球队")
                    return false;
                }
                var rq = /^\d{4}-\d{2}-\d{2}$/
                if (!rq.test($("[name=birthday]").val())){
                    alert("日期格式错误");
                    return false;
                }
            })
        })
    </script>
</head>
<body>

<div style="margin: 0px auto;width: 520px">
    <h1 style="text-align: center">修改球员信息</h1>
    <form action="/plays/update" method="post">
        <input type="hidden" name="pid" th:value="${play.pid}"/>
        <table width="520px">
            <tr>
                <td>球员姓名：</td>
                <td><input type="text" name="pname" th:value="${play.pname}"></td>
            </tr>
            <tr>
                <td>出生日期：</td>
                <td><input type="text" name="birthday" th:value="${#dates.format(play.birthday,'yyyy-MM-dd')}"></td>
            </tr>
            <tr>
                <td>球员身高：</td>
                <td><input type="text" name="height" th:value="${play.height}"></td>
            </tr>
            <tr>
                <td>球员体重：</td>
                <td><input type="text" name="weight" th:value="${play.weight}"></td>
            </tr>
            <tr>
                <td>球员位置：</td>
                <td>
                    <input type="radio" name="position" value="控球后卫" th:checked="${play.position!=null}?${play.position=='控球后卫'}">控球后卫
                    <input type="radio" name="position" value="得分后卫" th:checked="${play.position!=null}?${play.position=='得分后卫'}">得分后卫
                    <input type="radio" name="position" value="小前锋" th:checked="${play.position!=null}?${play.position=='小前锋'}">小前锋
                    <input type="radio" name="position" value="中锋" th:checked="${play.position!=null}?${play.position=='中锋'}">中锋
                </td>
            </tr>
            <tr>
                <td>所属球队：</td>
                <td>
                    <select name="cid">
                        <option value="">--请选择--</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>相关操作：</td>
                <td><input type="submit" value="修改">
                    <a href="/plays">
                        <input type="button" value="返回">
                    </a>
                </td>
            </tr>
        </table>
    </form>
</div>


</body>
</html>